package logic

import (
	"context"
	"shell/models/mysql"

	"shell/houserpc/houserpc"
	"shell/houserpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseAddLogic {
	return &HouseAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseAddLogic) HouseAdd(in *houserpc.HouseAddRequest) (*houserpc.HouseAddResponse, error) {
	// todo: add your logic here and delete this line
	var house mysql.House

	house = mysql.House{
		UserId:     in.UserId,
		Title:      in.Title,
		Cont:       in.Cont,
		Price:      float64(in.Price),
		Address:    in.Address,
		Area:       in.Area,
		HouseImage: "https://cn.bing.com/images/search?q=%e6%88%bf%e5%ad%90%e5%9b%be%e7%89%87&id=9F1D058A5C7899B99E5A80CFA8FE2BCD8F6D54C7&FORM=IACFIR",
	}
	mysql.DB.Debug().Create(&house)
	return &houserpc.HouseAddResponse{
		HouseId: int64(house.ID),
	}, nil
}
